import Taro from '@tarojs/taro'
import REquals from 'ramda/src/equals'

/**
 * 验证 =>  用户输入手机号是否有效
 * @param phone 必填
 */
export const isPhone: (phone: string) => boolean = (phone: string) => /^1[3-9]\d{9}$/.test(phone.trim())

/**
 * 验证 => 邮箱
 */
export const isEmail: (email: string) => boolean = (email: string) => /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email)

/**
 * 用户数据昵称
 */
export const isChinese: (value: string) => boolean = (value: string) => new RegExp(/[\u00A1-\uFFFF]/).test(value)

/**
 * 验证 => account
 */
export const isAccount: (account: string) => boolean = (account: string) => /^[\u4E00-\u9FA5A-Za-z0-9_]+$/.test(account)

/**
 * 判断用户登录是否失效
 */
export const isLogin: () => boolean = () => {
  const loginStatus = (Taro.getStorageSync('authorization') === '' && false) || true

  return loginStatus
}

/**
 * 判断两个对象是否相等
 * @param prevProps
 * @param nextProps
 */
export const IsEquals = (prevProps, nextProps) => REquals(prevProps, nextProps)
